<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
    <title>充值订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <!-- load css -->
    <link rel="stylesheet" th:href="@{/css/font.css}" />
	<link rel="stylesheet" th:href="@{/css/xadmin.css}" />
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body class="layui-anim layui-anim-fadein">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a>合作商管理</a>
        <a><cite>充值订单</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input id="partner_order_no" type="text" name="partner_order_no"   placeholder="合作商单号" autocomplete="off" class="layui-input">
          <input id="goods_link" type="text" name="goods_link"   placeholder="商品链接" autocomplete="off" class="layui-input">
          <input id="amount" type="text" name="amount"  placeholder="订单金额" autocomplete="off" class="layui-input">
          <div class="layui-input-inline">
            <select id="type" name="type">
              <option value="">类型</option>
              <option value="1">住宅</option>
              <option value="2">店铺</option>
              <option value="3">企事业</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="status" name="status">
              <option value="">订单状态</option>
              <option value="-3">手动取消</option>
              <option value="-2">充值失败</option>
              <option value="-1">待检测</option>
              <option value="0">待充值</option>
              <option value="1">部分充值</option>
              <option value="2">充值成功</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="charge_status" name="charge_status">
              <option value="">充值状态</option>
              <option value="-1">充值失败</option>
              <option value="0">未充值</option>
              <option value="1">部分充值</option>
              <option value="2">充值成功</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="notify_status" name="notify_status">
              <option value="">回调状态</option>
              <option value="0">未回调</option>
              <option value="1">已回调</option>
            </select>
          </div>
          <button id="searchBtn" data-type="reload" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
          <button class="layui-btn" style="margin-left: 30px;" onclick="downLoadMoban()">下载商品模板</button>
        </div>
      </div>
      <xblock>
      <button class="layui-btn" onclick="x_admin_show('发起充值','/partner/chargeAccountYouKa/addPage.html',455,400)"><i class="layui-icon"></i>新增</button>
      <button id="batchFail" class="layui-btn" >批量失败</button>
      <button id="importData" class="layui-btn">批量导入</button>
      <button class="layui-btn" style="float: right;" onclick="exportExcel()">导出订单</button>
      </xblock>
      <table class="layui-hide" id="table1" lay-filter="tool1"></table>
      <script type="text/html" id="bar1">
		{{#  if(d.charge_status != 2){ }}
	 	 <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">取消订单</a>
		{{# } }}
	 </script>
      </div>
<script type="text/html" id="chargeStatusTpl">
{{#   if(d.charge_status == -1){ }}
<span style="color: red;">充值失败</span>
{{#  }else if(d.charge_status == 0){ }}
<span>未充值</span>
{{#  }else if(d.charge_status == 1){  }}
<span style="color: blue;">部分充值</span>
{{#  }else if(d.charge_status == 2){  }}
<span style="color: green;">充值成功</span>
{{#  }  }}
</script>
<script type="text/html" id="notifyStatusTpl">
{{#   if(d.notify_status == 0){ }}
<span>未回调</span>
{{#  }else if(d.notify_status == 1){  }}
<span style="color: green;">已回调</span>
{{#  }  }}
</script>
<script type="text/html" id="statusTpl">
{{#  if(d.status == -3){  }}
<span style="color: red;">手动取消</span>
{{#  }else if(d.status == -2){  }}
<span style="color: red;">充值失败</span>
{{#  }else if(d.status == -1){  }}
<span style="color: blue;">待检测</span>
{{#  }else if(d.status == 0){  }}
<span>待充值</span>
{{#  }else if(d.status == 1){  }}
<span style="color: blue;">部分充值</span>
{{#  }else if(d.status == 2){  }}
<span style="color: green;">充值成功</span>
{{#  }  }}
</script>
<script type="text/html" id="typeTpl">
{{#  if(d.type == 1){  }}
<span style="color: green;">住宅</span>
{{#  }else if(d.type == 2){  }}
<span style="color: blue;">店铺</span>
{{#  }else if(d.type == 3){  }}
<span style="color: blue;">企事业</span>
{{#  }else if(d.type == 4){  }}
<span style="color: blue;">商铺</span>
{{#  }  }}
</script>
<script>
function downLoadMoban()
{
	 window.open('[[@{/doc/导入商品模板.xlsx}]]');
}
function exportExcel()
{
	var postData={
        'partner_order_no':$('#partner_order_no').val(),
        'goods_link': $('#goods_link').val(),
        'amount': $('#amount').val(),
        'type': $('#type').val(),
        'status': $('#status').val(),
        'charge_status': $('#charge_status').val(),
        'notify_status': $('#notify_status').val(),
    };
	var tempform = document.createElement("form");      
    tempform.action = '[[@{/partner/chargeAccountYouKa/orderExport.html}]]';
    tempform.target = "_blank";
    tempform.method = "post";      
    tempform.style.display = "none"; 
	for (var x in postData) { 
		var opt = document.createElement("input");      
		opt.name = x;      
        opt.value = postData[x];      
        tempform.appendChild(opt);      
    }      
    document.body.appendChild(tempform);
    tempform.submit();     
}
      layui.use(['laydate', 'laypage', 'table', 'upload'], function(){
        var laydate = layui.laydate,
        table = layui.table, //表格
        laypage = layui.laypage, //分页
        upload = layui.upload;
        //执行一个 table 实例
        table.render({
          elem: '#table1'
          ,height: 680
          ,limit: 15
          ,limits:[15,20,30,40,50,100]
          ,url: '[[@{/partner/chargeAccountYouKa/list.html}]]' //数据接口
          ,id:'table1'
          ,page: true
          ,cols: [
           [
           /*  {field: 'id', title: 'ID', width:'7%', sort: true, align:'center',fixed: 'left'} */
            {field: 'phone', title: '店铺账号', width:'10%', align:'center',fixed: 'center'}
             ,{field: 'item_id', title: '商品ID', width:'10%', align:'center'}
            ,{field: 'goods_link', title: '商品链接', width:'10%', align:'center'}
            ,{field: 'amount', title: '商品金额', align:'center', width:'6%'}
          ]
          ]
        });
        $('#searchBtn').on('click', function(){
        	var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        	table.reload('table1', {
    	        page: {
    	          curr: 1 //重新从第 1 页开始
    	        }
    	        ,where: {
    	            'partner_order_no':$('#partner_order_no').val(),
    	            'goods_link': $('#goods_link').val(),
    	            'amount': $('#amount').val(),
    	            'type': $('#type').val(),
    	            'status': $('#status').val(),
    	            'charge_status': $('#charge_status').val(),
    	            'notify_status': $('#notify_status').val(),
    	        }
    	      });
        	layer.close(index);
       });
        
        $('#batchFail').on('click', function(){
        	layer.confirm('确认操作？', function(index){
                $.post('[[@{/partner/chargeAccountYouKa/batchFail.html}]]',{},function(data){
              	  layer.close(index);
              	  layer.msg(data.msg);
              	  if(data.code==0)
              	  {
              		  table.reload('table1', {
                	        page: {
                	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                	        }
                	        ,where: {
                	        	'partner_order_no':$('#partner_order_no').val(),
                	            'goods_link': $('#goods_link').val(),
                	            'amount': $('#amount').val(),
                	            'type': $('#type').val(),
                	            'status': $('#status').val(),
                	            'charge_status': $('#charge_status').val(),
                	            'notify_status': $('#notify_status').val(),
                	        }
                	      });
              	  }
                })
              });
       });
        
      //监听工具条
        table.on('tool(tool1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data //获得当前行数据
          ,layEvent = obj.event; //获得 lay-event 对应的值
          if(layEvent === 'cancel'){
        	  layer.confirm('确认取消订单？', {
        		  btn: ['确认','取消'] //按钮
        		}, function(){
        			 $.post('[[@{/partner/chargeAccountYouKa/cancel.html}]]',{'id':data.id},function(data)
               	          {
           			  		layer.msg(data.msg);
               	      		if(data.code==0)
               	      		{
               	      			//layer.alert(data.msg, {icon: 6},function () {
               	      				table.reload('table1', {
                                 	        page: {
                                 	        	curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                                 	        }
                                 	        ,where: {
                                 	        	'id': $('#id').val(),
                                	        	'partner_id': $('#partner_id').val(),
                                	            'partner_order_no':$('#partner_order_no').val(),
                                	            'goods_link': $('#goods_link').val(),
                                	            'amount': $('#amount').val(),
                                	            'type': $('#type').val(),
                                	            'status': $('#status').val(),
                                	            'charge_status': $('#charge_status').val(),
                                	            'notify_status': $('#notify_status').val(),
                                 	        }
                                 	      });
            	                  // });
               	      		}
               	          });
        		}, function(){
        			layer.msg('已取消', {icon: 1});
        		});
          }else if(layEvent === 'callback'){
        	 
        	}
        });
      
        upload.render({
            elem: "#importData",//导入id
            url: "[[@{/partner/chargeAccountYouKa/importOrder.html}]]",
            accept: "file",
            exts: 'xls|xlsx|xlsm|xlt|xltx|xltm',
            done: function (data) {
          	layer.msg(data.msg);
          	table.reload('table1', {
      	        page: {
      	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
      	        }
      	        ,where: {
      	        	'partner_order_no':$('#partner_order_no').val(),
    	            'goods_link': $('#goods_link').val(),
    	            'amount': $('#amount').val(),
    	            'type': $('#type').val(),
    	            'status': $('#status').val(),
    	            'charge_status': $('#charge_status').val(),
    	            'notify_status': $('#notify_status').val(),
      	        }
      	      });
            }
        });
      });
    </script>
  </body>
</html>
